/**
 * 用户相关rest api
 */
import request from '@/utils/request'

//API常量
const APIS = {
    V1: "/v1"
}

function queryByPaging(page, size, conditions) {
    return request({
        url: APIS.V1 + `/system/resource/list/${page}/${size}`,
        method: 'GET',
        params: conditions
    })
}

function deleteById(id) {
    return request({
        url: APIS.V1 + `/system/resource/${id}`,
        method: 'DELETE',
    })
}

function saveOrUpdate(resource) {
    return request({
        url: APIS.V1 + `/system/resource`,
        method: 'POST',
        data: resource
    })
}

/**
 * 分页查询该角色拥有的权限之外的权限
 */
 function exclusiveLoadPermissionsByPage(roleId, page, size) {
    return request({
        url: APIS.V1 + `/system/permission/exclusive-list/${roleId}/${page}/${size}`,
        method: 'GET',
    })
}
/**
 * 角色树形菜单
 */
function listTree() {
    return request({
        url: APIS.V1 + `/system/permission/listTree`,
        method: 'GET',
    })
}

/**
 * 分页查询该角色的所有权限
 */
function loadRolePermissionsByPage(roleId, page, size) {
    return request({
        url: APIS.V1 + `/system/permission/${roleId}/list/${page}/${size}`,
        method: 'GET',
    })
}


function listByFuzzyMatching(roleId, page, size, key) {
    if (key == '' || key == undefined) {
        key=null;
    }
    return request({
        url: APIS.V1 + `/system/permission/list/fuzzy/${roleId}/${page}/${size}/${key}`,
        method: 'GET',
    })
}

export default {
    queryByPaging, deleteById, saveOrUpdate, exclusiveLoadPermissionsByPage
    , loadRolePermissionsByPage, listByFuzzyMatching,listTree
}